package com.yamanyar.weebill.domain;

import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

/**
 * 
 * <code>ActionPath</code> object contains a set of <code>Action</code>s.
 * In order to understand use of <code>ActionPath</code> please check the
 * javadoc of <code>Action</code>
 * 
 * @see Action.
 * 
 * @author Kaan Yamanyar
 * 
 */
@Entity
public class ActionPath implements java.io.Serializable {

	private static final long serialVersionUID = -2111273563023531102L;

	private Long id;

	private String name;

	private String description;

	/*
	 * Since actionPathElements needs to be ordered, we used TreeSet. That's why
	 * ActionPathElement has field named 'order' and compare method of
	 * ActionPathElement is build around it.
	 */
	private Set<ActionPathElement> actionPathElements = new TreeSet<ActionPathElement>();

	public ActionPath() {
	}

	public ActionPath(Long id, String name) {
		this.id = id;
		this.name = name;
	}

	public ActionPath(Long id, String name, String description,
			Set<ActionPathElement> actionPathElements) {
		this.id = id;
		this.name = name;
		this.description = description;
		this.actionPathElements = actionPathElements;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "name", unique = true, nullable = false, length = 50)
	@NotNull
	@Length(max = 50)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "description", length = 250)
	@Length(max = 250)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name = "actionPathId")
	// actionPathId will be created in ActionPathElement object's table
	// @Collection(child = true, inverse = "actionPath")
	public Set<ActionPathElement> getActionPathElements() {
		return this.actionPathElements;
	}

	public void setActionPathElements(Set<ActionPathElement> actionPathElements) {
		this.actionPathElements = actionPathElements;
	}

}